OT: Sql select jak vybrat zaznamy rozgrupovane dle mesicu?
Otázka od: David Michal
24. 10. 2002 11:51
Zdravim,
Pouzivam MSSQL2000, nyni resim nasledujici problem.
V tabulce TimeSheet mam zhruba tyto polozky:
ID, DateWork, Hours (neni to presne ale k popisu problemu to staci).
Ve fieldu DateWork ukladam datum(den mesic rok). A do fieldu Hours ukladam
pocet odpracovany hodin v danem dnu.
A otazka zni: Jak udelat select, ktery by mi ukazal soucet hodin pro kazdy
mesic?
Tzn. neco jako:
Select SUM(Hours) as SHours From TimeSheet Group By Month
Jenomze jak z toho dostat tu hodnotu month?
Diky za kazdy napad,
David
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.406 / Virus Database: 229 - Release Date: 21/10/2002
Odpovedá: Roman
24. 10. 2002 14:30
> Zdravim,
> Pouzivam MSSQL2000, nyni resim nasledujici problem.
> V tabulce TimeSheet mam zhruba tyto polozky:
> ID, DateWork, Hours (neni to presne ale k popisu problemu to staci).
> Ve fieldu DateWork ukladam datum(den mesic rok). A do fieldu Hours ukladam
> pocet odpracovany hodin v danem dnu.
> A otazka zni: Jak udelat select, ktery by mi ukazal soucet hodin pro kazdy
> mesic?
> Tzn. neco jako:
> Select SUM(Hours) as SHours From TimeSheet Group By Month
> Jenomze jak z toho dostat tu hodnotu month?
Neslo by neco jako:
select extract(month from datework),sum(hours) from timesheet group by
extract(month from datework);
Roman
==============================
http://kouzelne.misto.cz
Odpovedá: Král Jirka
24. 10. 2002 12:39
>>ID, DateWork, Hours (neni to presne ale k popisu problemu to staci). Ve
fieldu DateWork ukladam datum(den mesic rok). A do fieldu Hours ukladam pocet
odpracovany hodin v danem dnu. A otazka zni: Jak udelat select, ktery by mi
ukazal soucet hodin pro kazdy mesic? Tzn. neco jako: Select SUM(Hours) as
SHours From TimeSheet Group By Month Jenomze jak z toho dostat tu hodnotu
month? Diky za kazdy napad, David
datepart(m.
Odpovedá: Zálešák Tomáš
24. 10. 2002 12:47
> Pouzivam MSSQL2000, nyni resim nasledujici problem.
> V tabulce TimeSheet mam zhruba tyto polozky:
> ID, DateWork, Hours (neni to presne ale k popisu problemu to staci).
> Ve fieldu DateWork ukladam datum(den mesic rok). A do fieldu
> Hours ukladam pocet odpracovany hodin v danem dnu.
> A otazka zni: Jak udelat select, ktery by mi ukazal soucet
> hodin pro kazdy mesic?
> Tzn. neco jako:
> Select SUM(Hours) as SHours From TimeSheet Group By Month
> Jenomze jak z toho dostat tu hodnotu month?
SELECT
YEAR(DateWork) AS Rok,
MONTH(DateWork) AS Mesic,
SUM(Hours) AS Suma
FROM TimeSheet
GROUP BY YEAR(DateWork), MONTH(DateWork)
ORDER BY 1, 2
Tomas Zalesak
Odpovedá: Král Jirka
24. 10. 2002 15:47
>>ID, DateWork, Hours (neni to presne ale k popisu problemu to staci).
>>Ve fieldu DateWork ukladam datum(den mesic rok). A do fieldu Hours
>>ukladam pocet odpracovany hodin v danem dnu. A otazka zni: Jak udelat
>>select, ktery by mi ukazal soucet hodin pro kazdy mesic? Tzn. neco
>>jako: Select SUM(Hours) as SHours From TimeSheet Group By Month
>>Jenomze jak z toho dostat tu hodnotu month? Diky za kazdy napad,
>>David
select datepart(m, datework), sum(hours)
from x
group by datepart(m, datework)
sorry za predesly mejl, aninevimjak se mi podalio zavadit o "Odeslat"
J.